home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / kernel / amf.1 next >
Text File  |  1989-03-16  |  10KB  |  365 lines

  1. Path: xanth!ames!mailrus!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i068:  amf - add memory forever
  5. Message-ID: <12283@swan.ulowell.edu>
  6. Date: 16 Mar 89 15:54:58 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 354
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: U211344@HNYKUN11.BITNET (Olaf 'Rhialto' Seibert)
  12. Posting-number: Volume 89, Issue 68
  13. Archive-name: kernel/amf.1
  14.  
  15. This is an AddMem that installs a ResModule in order to initialize the
  16. extra memory as early in the system bootstrap as possible.
  17.  
  18. [uuencoded executables included.  ..Bob]
  19.  
  20. #    This is a shell archive.
  21. #    Remove everything above and including the cut line.
  22. #    Then run the rest of the file through sh.
  23. #----cut here-----cut here-----cut here-----cut here----#
  24. #!/bin/sh
  25. # shar:    Shell Archiver
  26. #    Run the following text with /bin/sh to create:
  27. #    Amf.c
  28. #    amf.uu
  29. #    Clobber.c
  30. #    clobber.uu
  31. #    makefile
  32. # This archive created: Thu Mar 16 10:50:31 1989
  33. cat << \SHAR_EOF > Amf.c
  34. /*
  35.  *  AddMemForever - Copyright (C) 1989 by Olaf Seibert
  36.  *
  37.  *  This is an AddMem that installs a ResModule in order to initialize
  38.  *  the extra memory as early in the system bootstrap as possible.
  39.  *
  40.  *  Sigh, many kludges for the Manx assembler...
  41.  *
  42.  *  This is free software. There is no warranty whatsoever. If this
  43.  *  program proves defective, you assume all costs ... etc bla bla bla.
  44.  *  In short: For distribution refer to the GNU General Public Licence.
  45.  *
  46.  */
  47.  
  48. #include <exec/types.h>
  49. #include <exec/nodes.h>
  50. #include <exec/memory.h>
  51. #include <exec/resident.h>
  52. #include <exec/execbase.h>
  53.  
  54. #ifndef TAG_PRIORITY
  55. #define TAG_PRIORITY    115
  56. #endif
  57.  
  58. #define INDIRECT        0x80000000
  59.  
  60. extern void *AllocMem();
  61. extern struct Resident *FindResident();
  62. extern long TypeOfMem();
  63.  
  64. /* Whose dumb idea was it to type ExecBase.KickCheckSum an APTR ? */
  65. extern APTR SumKickData();
  66.  
  67. /* 'cuz they are in the code segment out of the compiler's control... */
  68. extern void BeginLabel(), EndLabel(), Init(), Base(), Size();
  69.  
  70. extern char Name[], IdString[];
  71. extern struct Resident Resident;
  72. extern struct MemList MemList;
  73. extern long ResModules[], KickTagPtr[];
  74.  
  75. #asm
  76.  
  77. .begin:
  78.         move.l  a0,-(sp)
  79.         move.l  d0,-(sp)
  80.         bsr.s   __main
  81.         lea     8(sp),sp
  82.         rts
  83.  
  84. #endasm
  85.  
  86. struct ExecBase *SysBase;
  87.  
  88. long _main(d0, a0)
  89. long d0;
  90. char *a0;
  91. {
  92.     register char *CopyOfModule;
  93.     register long ModuleSize;
  94.     register long Relocation;
  95.  
  96.     SysBase = *(struct ExecBase **)4;
  97.  
  98.     if (TypeOfMem(*(long *)Base + sizeof(struct MemHeader)) == 0)
  99.         Init();                 /* Add the memory now */
  100.  
  101.     if (FindResident(Name))
  102.         return 0;               /* Already resident */
  103.  
  104.     ModuleSize = (char *)EndLabel - (char *)BeginLabel;
  105.     CopyOfModule = AllocMem(ModuleSize, MEMF_CHIP|MEMF_PUBLIC);
  106.  
  107.     if (CopyOfModule == NULL)
  108.         return 20;              /* This would be very weird */
  109.  
  110.     Relocation = CopyOfModule - (char *)BeginLabel;
  111.  
  112.     Resident.rt_MatchTag = (struct Resident *)CopyOfModule;
  113.     Resident.rt_EndSkip = (APTR)(CopyOfModule + ModuleSize);
  114.     Resident.rt_Name += Relocation;         /* char * */
  115.     Resident.rt_IdString += Relocation;     /* char * */
  116.     Resident.rt_Init = (APTR)((char *) Resident.rt_Init + Relocation);
  117.  
  118.     MemList.ml_Node.ln_Succ = (struct Node *)SysBase->KickMemPtr;
  119.     MemList.ml_Node.ln_Name += Relocation;  /* char * */
  120.     MemList.ml_ME[0].me_Addr = (APTR)CopyOfModule;
  121.     MemList.ml_ME[0].me_Length = ModuleSize;
  122.  
  123.     Disable();
  124.  
  125.     /* Set up link for Resident list */
  126.     ResModules[0] = (long) CopyOfModule;
  127.     if (ResModules[1] = (long) SysBase->ResModules)
  128.         ResModules[1] |= INDIRECT;
  129.  
  130.     /* Set up link for KickTagPtr list */
  131.     KickTagPtr[0] = (long) CopyOfModule;
  132.     if (KickTagPtr[1] = (long) SysBase->KickTagPtr)
  133.         KickTagPtr[1] |= INDIRECT;
  134.  
  135.     CopyMem((char *)BeginLabel, CopyOfModule, ModuleSize);
  136.  
  137.     SysBase->ResModules = (APTR)((char *)&ResModules[0] + Relocation);
  138.     SysBase->KickTagPtr = (APTR)((char *)&KickTagPtr[0] + Relocation);
  139.     SysBase->KickMemPtr = (APTR)((char *)&MemList + Relocation);
  140.     SysBase->KickCheckSum = SumKickData();
  141.  
  142.     Enable();
  143.  
  144.     return 0;
  145. }
  146.  
  147. /* Manx seems to be missing a binding for SumKickData() */
  148.  
  149. #asm
  150.  
  151. _LVOSumKickData equ -$264
  152.  
  153. _SumKickData:
  154.         move.l  4,a6
  155.         jmp     _LVOSumKickData(a6)
  156.  
  157. #endasm
  158.  
  159. /* From here will be copied to remain resident: */
  160.  
  161. #asm
  162.  
  163. _BeginLabel:
  164.  
  165. #endasm
  166.  
  167. /*
  168.  *  This struct Resident must be linked on the ResModules and
  169.  *  and KickTagPtr lists. It must be the first thing in the
  170.  *  resident module. (That's what our code assumes, it is
  171.  *  no system requirement.)
  172.  */
  173.  
  174. struct Resident Resident = {
  175.     RTC_MATCHWORD,      /* rt_MatchWord */
  176.     NULL,               /* rt_MatchTag */       /* <-- Relocate */
  177.     NULL,               /* rt_EndSkip */        /* <-- Relocate */
  178.     RTF_COLDSTART,      /* rt_Flags */
  179.     1,                  /* rt_Version */
  180.     NT_UNKNOWN,         /* rt_Type */
  181.     TAG_PRIORITY,       /* rt_Priority */
  182.     Name,               /* rt_Name */           /* <-- Relocate */
  183.     IdString,           /* rt_IdString */       /* <-- Relocate */
  184.     (APTR)&Init         /* rt_Init */           /* <-- Relocate */
  185. };
  186.  
  187. /*
  188.  *  This MemEntry structure describes the memory from BeginLabel to
  189.  *  EndLabel, and must be on the KickMemPtr list (not a List).
  190.  */
  191.  
  192. struct MemList MemList = {
  193.     {                   /* ml_Node */
  194.         NULL,               /* ln_Next, singly linked list */
  195.         NULL,               /* ln_Prev, unused */
  196.         NT_UNKNOWN,         /* ln_Type */
  197.         0,                  /* ln_Pri */
  198.         Name                /* ln_Name */       /* <-- Relocate */
  199.     },
  200.     1,                  /* ml_NumEntries */
  201.     NULL,               /* me_Addr */           /* <-- Relocate */
  202.     0,                  /* me_Size */           /* <-- Set */
  203. };
  204.  
  205. char Name[]     = "addmem.tag";
  206. char IdString[] = "AddMemForever by Olaf Seibert (5 march 1989)\r\n";
  207.  
  208. long KickTagPtr[2] = { 0, 0 };
  209. long ResModules[2] = { 0, 0 };
  210.  
  211. #asm
  212.  
  213. _LVOAddMemList  equ -$26a
  214. MEMF_PUBLIC     equ 1
  215. MEMF_FAST       equ 4
  216.  
  217. _Init:
  218.         movem.l  a6/d2,-(sp)
  219.  
  220. ;;;;
  221. ;
  222. ;   Allow the user NOT to add memory if he presses the left
  223. ;   mouse button.
  224.  
  225.         btst.b  #6,$bfe001
  226.         beq.s   quit
  227.  
  228. ;;;;
  229. ;
  230. ;   It is a good idea to first test if there really is some
  231. ;   memory when it is supposed to be there. We test the first
  232. ;   longword, which will be clobbered by AddMemList anyway.
  233.  
  234.         move.l  _Base(pc),a0    ; Base address
  235.         clr.l   (a0)
  236.         tst.l   (a0)
  237.         bne.s   quit            ; Must be no or bad memory
  238.         move.l  #$55555555,d0
  239.         move.l  d0,(a0)
  240.         cmp.l   (a0),d0
  241.         bne.s   quit            ; Must be no or bad memory
  242.         asl.l   #1,d0
  243.         move.l  d0,(a0)
  244.         cmp.l   (a0),d0
  245.         bne.s   quit            ; Must be no or bad memory
  246.  
  247. ;;;;
  248. ;
  249. ;   We now believe there is memory.
  250.  
  251.         move.l  _Size(pc),d0    ; Size
  252.         move.l  #MEMF_FAST+MEMF_PUBLIC,d1
  253.         moveq.l #0,d2           ; Priority 0
  254.         lea     _Name(pc),a1    ; Name
  255.         move.l  4,a6            ; AbsExecBase
  256.         jsr     _LVOAddMemList(a6)
  257.  
  258. ;;;;
  259. ;
  260. ;   We are done here. I don't know what the return value should be...
  261.  
  262. quit:
  263.         moveq.l #0,d0
  264.         movem.l (sp)+,a6/d2
  265.         rts
  266.  
  267.  
  268. _Base:  dc.l MEM_BASE
  269. _Size:  dc.l MEM_SIZE
  270.  
  271. _EndLabel:
  272.  
  273. #endasm
  274. SHAR_EOF
  275. cat << \SHAR_EOF > amf.uu
  276.  
  277. begin 644 AddMemForever
  278. M```#\P`````````#``````````(```"O``````````$```/I````KR\(+P!A-
  279. M!D_O``A.=4Y5``!(YPP@(_@`!``````@>0```EA(:``@3KD```*L6$]*@&8`[
  280. M``A.N0```A!(>0```<1.N0```IY83TJ`9P``#'``3-\$,$Y=3G5!^0```F!#.
  281. M^0```9*1R2@(2'@``R\$3KD```)T4$\D0"`*9@``!G`48,Y!^0```9(B2I/(H
  282. M*@DCR@```90@2M'$(\@```&8V[D```&@V[D```&DV[D```&H('D`````(^@")
  283. M(@```:S;N0```;8CR@```;PCQ````<!.N0```HHCR@```@@@>0`````CZ`$L'
  284. M```"#$JH`2QG```*"/D`!P```@PCR@```@`@>0`````CZ`(F```"!$JH`B9GV
  285. M```*"/D`!P```@0O!"\*2'D```&23KD```)@3^\`#"!Y`````$/Y```"""`%/
  286. MT(DA0`$L('D`````0_D```(`(`70B2%``B8@>0````!#^0```:P@!=")(4`"H
  287. M(DZY```!BB!Y`````"%``BI.N0```I1P`&``_L@L>``$3N[]G$K\````````0
  288. M```!`0!S```!Q````=````(0`````````````````<0``0``````````861D,
  289. M;65M+G1A9P``061D365M1F]R979E<B!B>2!/;&%F(%-E:6)E<G0@*#4@;6%R2
  290. M8V@@,3DX.2D-"@```````````````````````$CG(`((.0`&`+_@`6<R('H`Q
  291. M.$*02I!F*"`\555552"`L)!F'..`(("PD&84(#H`'G(%=`!#^O]^+'@`!$ZN"
  292. M_99P`$S?0`1.=0`@````(```3.\#```$("\`#"QY`````$[N_9!.^0```GI,/
  293. M[P`#``0L>0````!.[O\Z+'D`````3N[_B"QY`````$[N_X(B;P`$+'D`````4
  294. M3N[_H"QY`````")O``1.[OWJ``````/L````)0`````````>````*````#8`(
  295. M```\````0@```%H```!@````<````(0```"0````F@```*````"F````K```(
  296. M`+H```#`````Q@```,P```#2````V````.8```#V````_````0H```$:```!U
  297. M)````2H```$Z```!3@```6(```%P```!@````:````&D```!J````;8```)V,
  298. M````#@````(````8````L@```-X```$"```!-````4@```%<```!=@```FP`[
  299. M``*"```"C````I8```*D```"K@````````/R```#Z@````````/R```#ZP``%
  300. &``$```/RV
  301. ``
  302. end
  303. size 996
  304. SHAR_EOF
  305. cat << \SHAR_EOF > Clobber.c
  306. #include <exec/types.h>
  307. #include <exec/execbase.h>
  308.  
  309. struct ExecBase *SysBase;
  310.  
  311. _main()
  312. {
  313.     ++SysBase->KickCheckSum;
  314. }
  315.  
  316.  
  317.  
  318. SHAR_EOF
  319. cat << \SHAR_EOF > clobber.uu
  320.  
  321. begin 644 clobber
  322. M```#\P`````````#``````````(````F````$P````$```/I````)F`03E4`:
  323. M`"!L@`Y8J`(J3EU.=6%\0_D````,1?D````,M<EF#C(\``]K"'0`(L)1R?_\R
  324. M(\\````0+'@`!"/.````#$CG@(`(+@`$`2EG$$OZ``A.KO_B8`9"I_-?3G-#`
  325. M^@`D3J[^:"/`````%&8,+CP``X`'3J[_E&`&3KD````"4$].=61O<RYL:6)R:
  326. M87)Y`$GY``!__DYU```#[`````$`````````?`````8````!````%@```!P`S
  327. M```T````/@```&@```"2`````````_(```/J`````P`4````````````````E
  328. .`_(```/K`````0```_*2K
  329. ``
  330. end
  331. size 284
  332. SHAR_EOF
  333. cat << \SHAR_EOF > makefile
  334. #
  335. #   Makefile for AddMemForever
  336. #
  337. #   Compile without startup code, initialized data into code segment,
  338. #   and large code, data and integers.
  339.  
  340. MEMBASE = $$200000  # hex
  341. MEMSIZE = $$200000
  342.  
  343. amf:    amf.o
  344.     ln amf.o -lcl -w
  345.  
  346. AddMemForever: amf.o
  347.     ln amf.o -lcl -o $@
  348.  
  349. both:    amf AddMemForever
  350.  
  351. install: AddMemForever
  352.     Copy AddMemForever C:AddMem-2M
  353.  
  354. amf.o:    amf.asm
  355.     as -n amf.asm -EMEM_BASE=$(MEMBASE) -EMEM_SIZE=$(MEMSIZE)
  356.  
  357. amf.asm:amf.c
  358.     cc +x2 +blcd -a amf.c
  359. SHAR_EOF
  360. #    End of shell archive
  361. exit 0
  362. -- 
  363. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  364. Have five nice days.
  365.